function vertices = chooseBakeries(distances,wanderingDistances,limit)
% Choose where to locate bakeries

vertices = [0 0 0];
esize = max(size(distances));
tolerance = limit;

idw = sum(wanderingDistances);
% now to choose multiple vertices, first one is where closest to target
[dist,indices] = sort(idw);


vertices(1) = indices(1);

for n = 2:esize
    % first we fill the second choice
    if(vertices(2) == 0)
        
        % If it is far away enough
        if(distances(indices(n),vertices(1)) >= tolerance)
            vertices(2) = indices(n);        
        end;
    % This is our third choice
    elseif (vertices(3) == 0)
        
        if(distances(indices(n),vertices(1)) >= tolerance && distances(indices(n),vertices(2)) >= tolerance)
            vertices(3) = indices(n);        
        end;        
    end;
end;